# -*- coding: utf-8 -*-
# @Time    : 2024/11/29 上午9:35
# @Author  : wjx
# @Email   : kanxinxin@163.com
# @File    : base_page.py
# @Software: PyCharm
from time import sleep

from appium.webdriver.common.appiumby import AppiumBy as By


class BasePage:
    def __init__(self, driver):
        # 定义实例属性driver
        self.driver = driver

    def find_element(self, locator):
        """
        find_element方法，定位元素，定位器在这里解构
        :param locator:定位器
        :return:定位到的元素
        """
        return self.driver.find_element(*locator)

    def back(self):
        self.driver.press_keycode(4)

    def take_photo(self):
        # 定位器
        take_photo_locator = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().description("拍照")')
        take_photo_btn_locator = (
            By.ANDROID_UIAUTOMATOR, 'new UiSelector().resourceId("com.xiachufang:id/camera_take_photo")')

        self.find_element(take_photo_locator).click()
        sleep(1)
        self.find_element(take_photo_btn_locator).click()
        sleep(1)
        self.find_element(take_photo_btn_locator).click()
        sleep(1)
